package jsyf.oa.dao.wechartSec;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import jsyf.oa.entity.wechartSec.WechartDeviceEntity;
import jsyf.oa.idao.BaseDao;
import jsyf.oa.ientity.IBaseEntity;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Administrator on 2018/4/8.
 */
@Repository
public class WechartDeviceDao extends BaseDao {

    public WechartDeviceDao() {

        this.iBaseEntity = new WechartDeviceEntity();
    }
    @Override
    public IBaseEntity convertJson2Entity(JSONObject json) {
        return JSON.toJavaObject(json, WechartDeviceEntity.class);

    }

    public List<JSONObject> getJSONListByPage(String condition, Object[] params, int requestPage, int pageSize) {
        StringBuffer sql = new StringBuffer();
        sql.append(" SELECT ");
        sql.append(" * ");
        sql.append(" FROM ");
        sql.append(iBaseEntity.getTableName());
        sql.append(" WHERE 1=1 ");
        sql.append(condition);
        super.appendPageSql(sql, requestPage, pageSize);

        List<JSONObject> jsonList = super.queryForJsonList(sql.toString(), params);

        return jsonList;
    }

    public Integer getPageCount(String condition, Object[] params) {
        StringBuffer sql = new StringBuffer();
        sql.append(" SELECT COUNT(1) AS count FROM " + iBaseEntity.getTableName());
        sql.append(" WHERE 1=1 ");
        sql.append(condition);
        String count = super.queryForString(sql.toString(), params);
        return Integer.parseInt(count);
    }
}